/*
 * 原版接口
 */
import * as server from "@minecraft/server";
/*
 * 彼岸组件
 */
import * as magic_cable from "./magic_cable";
import * as servo_drive from "./servo_drive";
import * as machine_gate from "./machine_gate";
import * as magic_weapon from "./magic_weapon";
import * as energy_module from "./energy_module";
import * as storage_manage from "./storage_manage";
import * as mineral_project from "./mineral_project";
import * as farming_project from "./farming_project";
import * as obsidian_smelting from "./obsidian_smelting";
/*
 * 蛋白石数据
 */
import * as data_block from "../data/block";
/*
 * 蛋白石组件
 */
import * as realm_property from "../system/realm_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
/**
 * * 进行检测的默认标签
 */
const defaultState = 'STATE:rune_type';
/**
 ** 时间积分
 */
const tickScore = new Map<string, [string, number]>();
/**
 ** 常规类型 物品网络 申请
 */
let routineLogisticsRequest = new Map<string, server.Vector3>();
/**
 ** 跨越维度 物品网络 申请
 */
let surpassDimensionRequest = new Map<string, [server.Dimension, server.Vector3]>();
/**
 * * 方块组件参数 的 解构
 */
interface TICK_COMPONENT {
    /**
     ** 默认的方块状态的值
     */
    condition: string | number | boolean;
    /**
     ** 方块状态
     */
    state: server.BlockPermutation;
    /**
     ** 方块对象
     */
    block: server.Block;
    /**
     * * 方块维度
     */
    dimension: server.Dimension;
};
/**
 ** 方块计时器
 * 
 * 此方法为方块对象设置一个单调递增的计时器,
 * 当计时器的值达到或超过指定的时间节点时,
 * 执行一个回调函数,
 * 计时器用于跟踪每个方块的位置和积分,
 * 以便在特定条件下触发事件
 * 
 * @param {server.Block} block - 预约时钟事件的方块对象
 * 
 * @param {number} bounds - 触发事件的时间节点
 * 
 * @param {(block: server.Block) => void} after - 当计时器的值达到或超过界限时执行的事件回调函数
 * 
 * @returns {Error | void} - 错误对象或空值
 */
function blockTimer(block: server.Block, bounds: number, after: (block: server.Block) => void): Error | void {
    /**
     ** 方块位置
     */
    const position = math_tools.Vector.toString(block.location);
    /**
     ** 时间积分
     */
    const onTick = tickScore.get(position);
    // 创建时间积分
    if (!onTick || onTick[0] != block.typeId) tickScore.set(position, [block.typeId, 1]);
    // 判断与赋值事件积分
    else if (onTick && onTick[1] <= bounds) tickScore.set(position, [block.typeId, onTick[1] + 1]);
    // 执行事件
    else {
        // 移除当前方块位置的时间积分
        tickScore.delete(math_tools.Vector.toString(block.location));
        // 尝试执行回调函数
        try {
            return after(block);
        }
        catch (error) { return error as Error; }
    }
};
/**
 * * 方块时钟组件
 * 
 * @param source - 方块组件参数
 */
function TickComponentTrigger(source: server.BlockComponentTickEvent): TICK_COMPONENT {
    /**
     * * 方块对象
     */
    const block = source.block;
    /**
     * * 方块状态
     */
    const state = source.block.permutation;
    /**
     * * 方块维度
     */
    const dimension = source.dimension;
    /**
     * * 默认的方块状态的值
     */
    const condition = state.getState(defaultState) ?? 0;
    // 返回 方块组件 的 解构
    return { block, state, condition, dimension };
};
/**
 ** 虚无方块
 */
export function UnrealSpaceTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 修饰方块状态
            if (analysis.state.getState('STATE:stage') == 0) native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 2);
            // 预约时钟事件
            blockTimer(analysis.block, 20, block => block.setPermutation(server.BlockPermutation.resolve('minecraft:air')));
        }
    }
};
/**
 ** 虚空方块
 */
export function NihilitySpaceTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 播放音效
            analysis.dimension.playSound('use.stone', analysis.block.location);
            // 修改 方块属性
            switch (analysis.state.getState('STATE:value')) {
                case 0: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 1); break;

                case 1: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 2); break;

                case 2: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 3); break;

                case 3: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 4); break;

                case 4: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 5); break;

                case 5: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 6); break;

                case 6: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 7); break;

                case 7: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 8); break;

                case 8: native_tools.TrySetPermutation(analysis.block, 'STATE:value', 9); break;

                default:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 10);
                    analysis.dimension.playSound('beacon.activate', analysis.block.location);
                    analysis.block.setPermutation(server.BlockPermutation.resolve('minecraft:air'));
                    break;
            }
        }
    }
};
/**
 ** 基础总线
 */
export function BasicPipelineTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 判断方块的元素类型状态
            if (analysis.condition != 0 && analysis.condition != 9) magic_cable.defaultEvent(analysis.block, 'Xx-Yy-Zz', analysis.state);
            // 重置方块元素类型
            else if (analysis.condition == 9) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.X', analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag('data_tag:magic_cable.port_negative.X') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.X', analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag('data_tag:magic_cable.port_positive.X') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Y', analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag('data_tag:magic_cable.port_negative.Y') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Y', analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag('data_tag:magic_cable.port_positive.Y') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Z', analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag('data_tag:magic_cable.port_positive.Z') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Z', analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag('data_tag:magic_cable.port_negative.Z') ?? false);
            };
        }
    }
};
/**
 ** 脉冲锁存
 */
export function PulselatchTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', analysis.condition);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                magic_cable.LatchUpdateEvent(analysis.block);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            };
            // 判断方块的元素类型
            if (analysis.condition != 0 && analysis.state.getState('STATE:rune_note') == 0) beforeEvent();
            // 重置方块元素类型
            else if (analysis.condition != 0 && analysis.state.getState('STATE:rune_note') != 0) afterEvent();
            // 设置方块朝向属性
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.X', (analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag('data_tag:magic_cable.port_negative.X') || analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag('data_tag:magic_cable.logic_negative.X')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.X', (analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag('data_tag:magic_cable.port_positive.X') || analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag('data_tag:magic_cable.logic_positive.X')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Y', (analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag('data_tag:magic_cable.port_negative.Y') || analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag('data_tag:magic_cable.logic_negative.Y')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Y', (analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag('data_tag:magic_cable.port_positive.Y') || analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag('data_tag:magic_cable.logic_positive.Y')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Z', (analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag('data_tag:magic_cable.port_negative.Z') || analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag('data_tag:magic_cable.logic_negative.Z')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Z', (analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag('data_tag:magic_cable.port_positive.Z') || analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag('data_tag:magic_cable.logic_positive.Z')) ?? false);
        }
    }
};
/**
 ** 超导枢纽
 */
export function SuperOmphalosTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 判断方块的元素类型状态
            if (analysis.condition != 0 && analysis.condition != 9) magic_cable.SuperOmphalos(analysis.block, analysis.state);
            // 重置方块元素类型
            else if (analysis.condition == 9) native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 超导髓鞘
 */
export function SuperPulseTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 判断方块的元素类型状态
            if (analysis.condition != 0 && analysis.condition != 9) {
                /**
                 * * 射线动画 的 起点
                 */
                const start = analysis.block.location;
                /**
                 * * 修改 目标方块状态 并 返回 射线动画 的 终点
                 */
                const done = magic_cable.SuperPulse(analysis.block, analysis.state.getState('minecraft:block_face') as string);
                // 创建 路径规划
                achieve_plan.PathExecute.Create('超导髓鞘-射线动画', 1,
                    {
                        location_group: [start, done],
                        particles: ['constant:track_color_rainbow'],
                        offset: math_tools.Vector.CONSTANT_HALF,
                        dimension: analysis.dimension,
                        cooldown: 1,
                        speed: 1,
                    }
                );
            }
            // 重置方块元素类型
            else if (analysis.condition == 9) native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 传播许可
 */
export function EnableControlTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 判断方块的元素类型状态
            if (analysis.condition != 0 && analysis.condition != 9) {
                /**
                 ** 上方方块
                 */
                const above = analysis.block.above();
                /**
                 ** 下方方块
                 */
                const below = analysis.block.below();
                /**
                 ** 方块标签
                 */
                const tag = 'data_tag:magic_cable.open';
                // 检测 脉冲锁存 是否开启
                if (above?.hasTag(tag) || below?.hasTag(tag)) {
                    magic_cable.defaultEvent(analysis.block, 'Xx-0-Zz', analysis.state);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 1)
                }
                else if (!above?.hasTag(tag) && !below?.hasTag(tag)) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0)
                    native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0)
                }
            }
            // 重置方块元素类型
            else if (analysis.condition == 9) native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 红石侦测
 */
export function RedstoneDetectionTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 判断方块的红石能量强度
            magic_cable.RedstoneDetection(analysis.block, 'Xx-0-Zz');
        }
    }
};
/**
 ** 计数模块
 */
export function CountingModuleTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', 0);
                magic_cable.logicComponents(analysis.block, 'Xx-Yy-Zz');
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                const count = analysis.state.getState('STATE:count') as number;
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', count + 1);
            };
            if (analysis.state.getState('STATE:input') == analysis.state.getState('STATE:count')) beforeEvent();
            else if ((analysis.state.getState('STATE:input') != analysis.state.getState('STATE:count')) && analysis.state.getState('STATE:count') != 10) afterEvent();
        }
    }
};
/**
 ** 交互终端
 */
export function ControlPanelTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                switch (analysis.state.getState('minecraft:block_face')) {
                    case 'down':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-Y-Zz', analysis.state);
                        break;

                    case 'up':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-y-Zz', analysis.state);
                        break;

                    case 'north':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-Yy-Z', analysis.state);
                        break;

                    case 'south':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-Yy-z', analysis.state);
                        break;

                    case 'west':
                        magic_cable.interactiveTerminal(analysis.block, 'X-Yy-Zz', analysis.state);
                        break;

                    case 'east':
                        magic_cable.interactiveTerminal(analysis.block, 'x-Yy-Zz', analysis.state);
                        break;

                    default: break;
                };
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 2);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
            };
            if (analysis.state.getState('STATE:stage') == 1) beforeEvent();
            else if (analysis.state.getState('STATE:stage') == 2) afterEvent();
        }
    }
};
/**
 ** 逻辑非门
 */
export function LogicInverterTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 方块状态值
             */
            const face = analysis.state.getState('minecraft:block_face') as string;
            /**
             ** 方块标签
             */
            const tag = 'data_tag:magic_cable.open';
            // 判断设备朝向
            switch (face) {
                case 'up':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag(tag)) magic_cable.logicComponents(analysis.block, '0-y-0');
                    break;

                case 'down':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag(tag)) magic_cable.logicComponents(analysis.block, '0-Y-0');
                    break;

                case 'north':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag)) magic_cable.logicComponents(analysis.block, '0-0-Z');
                    break;

                case 'south':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag)) magic_cable.logicComponents(analysis.block, '0-0-z');
                    break;

                case 'east':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag)) magic_cable.logicComponents(analysis.block, 'x-0-0');
                    break;

                case 'west':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag)) magic_cable.logicComponents(analysis.block, 'X-0-0');
                    break;

                default: break;
            }
        }
    }
};
/**
 ** 逻辑异或
 */
export function ExclusiveOrTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * 获取目标方块
             * 
             * @param input - 方块偏移
             * 
             * @returns {server.Block | undefined} - 返回方块对象
             */
            const target = (input: server.Vector3): server.Block | undefined => analysis.block.offset(input);
            /**
             ** 方块状态值
             */
            const face = analysis.state.getState('minecraft:block_face') as string;
            /**
             ** 方块标签
             */
            const tag = 'data_tag:magic_cable.open';
            // 判断设备朝向
            switch (face) {
                case 'up':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-y-0');
                    break;

                case 'down':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-Y-0');
                    break;

                case 'north':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-0-Z');
                    break;

                case 'south':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-0-z');
                    break;

                case 'east':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, 'x-0-0');
                    break;

                case 'west':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, 'X-0-0');
                    break;

                default: break;
            };
            // 状态重置
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
        }
    }
};
/**
 ** 逻辑与门
 */
export function ExclusiveAndTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * 获取目标方块
             * 
             * @param input - 方块偏移
             * 
             * @returns {server.Block | undefined} - 返回方块对象
             */
            const target = (input: server.Vector3): server.Block | undefined => analysis.block.offset(input);
            /**
             ** 方块状态值
             */
            const face = analysis.state.getState('minecraft:block_face') as string;
            /**
             ** 方块标签
             */
            const tag = 'data_tag:magic_cable.open';
            // 判断方块状态
            switch (face) {
                case 'up':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-y-0');
                    break;

                case 'down':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-Y-0');
                    break;

                case 'north':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-0-Z');
                    break;

                case 'south':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-0-z');
                    break;

                case 'east':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, 'x-0-0');
                    break;

                case 'west':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, 'X-0-0');
                    break;

                default: break;
            };
            // 状态重置
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
        }
    }
};
/**
 ** 信号编译
 */
export function SignalCompilationTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                magic_cable.SignalCompilation(analysis.block, 'Xx-0-Zz', analysis.state)
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:index', 0);
            };
            if (analysis.state.getState('STATE:stage') == 0 && analysis.state.getState('STATE:rune_type') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 1);
            }
            else if (analysis.state.getState('STATE:stage') == 1) beforeEvent();
            else if (analysis.state.getState('STATE:stage') == 2) afterEvent();
        }
    }
};
/**
 ** 信号过滤
 */
export function SignalFilteringTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                magic_cable.signalProcessing(analysis.block, 'Xx-Yy-Zz', analysis.state)
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            };
            if (analysis.condition != 0 && analysis.condition != 9 && analysis.condition == analysis.state.getState('STATE:rune_note')) beforeEvent();
            if (analysis.condition != 0 && analysis.condition != 9 && analysis.condition != analysis.state.getState('STATE:rune_note')) afterEvent();
            else if (analysis.condition == 9) afterEvent();
        }
    }
};
/**
 ** 信号转化
 */
export function SignalConversionTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 判断方块的元素类型状态
            if (analysis.condition != 0 && analysis.condition != 9) magic_cable.signalProcessing(analysis.block, 'Xx-Yy-Zz', analysis.state);
            // 重置方块元素类型
            else if (analysis.condition == 9) native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 总线端口
 */
export function CablePortTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 判断方块的元素类型状态
            if (analysis.condition != 0 && analysis.condition != 9) {
                /**
                 ** 方块状态值
                 */
                const face = analysis.state.getState('minecraft:block_face') as string;
                switch (face) {
                    case 'up':
                        magic_cable.defaultEvent(analysis.block, '0-Yy-0', analysis.state);
                        break;

                    case 'down':
                        magic_cable.defaultEvent(analysis.block, '0-Yy-0', analysis.state);
                        break;

                    case 'north':
                        magic_cable.defaultEvent(analysis.block, '0-0-Zz', analysis.state);
                        break;

                    case 'south':
                        magic_cable.defaultEvent(analysis.block, '0-0-Zz', analysis.state);
                        break;

                    case 'east':
                        magic_cable.defaultEvent(analysis.block, 'Xx-0-0', analysis.state);
                        break;

                    case 'west':
                        magic_cable.defaultEvent(analysis.block, 'Xx-0-0', analysis.state);
                        break;

                    default: break;
                }
            }
            // 重置方块元素类型
            else if (analysis.condition == 9) native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 打包投送
 */
export function PackageDeliveryTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 方块状态值
             */
            const face = analysis.state.getState('minecraft:block_face') as string;
            // 执行功能
            storage_manage.Transmission(analysis.block, face);
            // 播放音效 与 粒子效果
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            // 状态重置
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 方块放置
 */
export function PlacementTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 执行功能
            storage_manage.Placement(analysis.block);
            // 播放音效 与 粒子效果
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            // 状态重置
            native_tools.TrySetPermutation(analysis.block, 'STATE:energy', math_tools.Random({ min: 0, max: 6 }, true));
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 物资收集
 */
export function CollectionTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 执行功能
            storage_manage.Collection(analysis.block, analysis.state);
            // 播放音效 与 粒子效果
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            // 状态重置
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 伺服基座
 */
export function SusceptorTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                /**
                 ** 查询方块标签
                 */
                const hasTag = (offset: server.Vector3, tag: string) => analysis.block.offset(offset)?.getTags().includes(tag) ?? false;
                // 使能 模块运行
                switch (analysis.condition) {
                    case 1:
                        if (hasTag({ x: 1, y: -1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_EAST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X+');
                        break;

                    case 2:
                        if (hasTag({ x: -1, y: -1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_WEST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X-');
                        break;

                    case 3:
                        if (hasTag({ x: 0, y: -1, z: 1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_SOUTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z+');
                        break;

                    case 4:
                        if (hasTag({ x: -0, y: -1, z: -1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_NORTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z-');
                        break;

                    default: break;
                };
                // 同步状态
                for (let index = 0; index <= 5; index++) {
                    /**
                     ** 方块标签
                     */
                    const tag = 'data_tag:servo_machine.value.' + index;
                    // 赋值 方块状态
                    if (hasTag(math_tools.Vector.CONSTANT_EAST, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_WEST, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_SOUTH, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_NORTH, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                };
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                /**
                 ** 方块状态值
                 */
                const direction = analysis.state.getState('STATE:direction') as number;
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction', 0);
                // 执行 功能
                switch (direction) {
                    case 1:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_EAST) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 1, y: index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    case 2:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_WEST) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: -1, y: index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    case 3:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 1 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    case 4:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_NORTH) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: -1 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    default: break;
                };
            };
            if (analysis.condition != 0) beforeEvent();
            else if (analysis.state.getState('STATE:direction') != 0) afterEvent();
        }
    }
};
/**
 ** 伺服牵引
 */
export function TractionTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                /**
                 ** 查询方块标签
                 */
                const hasTag = (offset: server.Vector3, tag: string) => analysis.block.offset(offset)?.getTags().includes(tag) ?? false;
                // 使能 模块运行
                switch (analysis.condition) {
                    case 1:
                        if (hasTag({ x: 1, y: 1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_EAST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X+');
                        break;

                    case 2:
                        if (hasTag({ x: -1, y: 1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_WEST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X-');
                        break;

                    case 3:
                        if (hasTag({ x: 0, y: 1, z: 1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_SOUTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z+');
                        break;

                    case 4:
                        if (hasTag({ x: -0, y: 1, z: -1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_NORTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z-');
                        break;

                    default: break;
                };
                // 同步状态
                for (let index = 0; index <= 5; index++) {
                    /**
                     ** 方块标签
                     */
                    const tag = 'data_tag:servo_machine.value.' + index;
                    // 赋值 方块状态
                    if (hasTag(math_tools.Vector.CONSTANT_EAST, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_WEST, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_SOUTH, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_NORTH, tag)) native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                };
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                /**
                 ** 方块状态值
                 */
                const direction = analysis.state.getState('STATE:direction') as number;
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction', 0);
                // 执行 功能
                switch (direction) {
                    case 1:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_EAST) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 1, y: -index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    case 2:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_WEST) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: -1, y: -index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    case 3:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 1 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    case 4:
                        for (let index = 0; index <= 5; index++) {
                            // 校验 状态
                            if (index != analysis.state.getState('STATE:value')) continue;
                            // 获取 锚点坐标
                            const anchor_0 = math_tools.Vector.toString(analysis.block as server.Vector3, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_NORTH) as server.Vector3, { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: -1 }) as server.Vector3, { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }) as server.Vector3, { delimiter: ' ' });
                            // 执行 方块命令
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        };
                        break;

                    default: break;
                };
            };
            if (analysis.condition != 0) beforeEvent();
            else if (analysis.state.getState('STATE:direction') != 0) afterEvent();
        }
    }
};
/**
 ** 驱动核心
 */
export function OmphalosTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 播放音效 与 粒子效果
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            // 状态重置
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', math_tools.Random({ min: 0, max: 6 }, true));
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            // 执行功能
            switch (analysis.condition) {
                case 1: servo_drive.Omphalos(analysis.block, 'X+'); break;
                case 2: servo_drive.Omphalos(analysis.block, 'X-'); break;

                case 3: servo_drive.Omphalos(analysis.block, 'Z+'); break;
                case 4: servo_drive.Omphalos(analysis.block, 'Z-'); break;

                case 5: servo_drive.Omphalos(analysis.block, 'Y+'); break;
                case 6: servo_drive.Omphalos(analysis.block, 'Y-'); break;

                default: break;
            }
        }
    }
};
/**
 ** 水平机关门
 */
export function PlaneGateTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 播放音效 与 粒子效果
            analysis.dimension?.playSound('close.iron_door', analysis.block.location);
            // 状态更改
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            // 执行功能
            machine_gate.PlaneGate(analysis.block);
        }
    }
};
/**
 ** 垂直机关门
 */
export function VerticalGateTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 播放音效 与 粒子效果
            analysis.dimension?.playSound('close.iron_door', analysis.block.location);
            // 状态更改
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            // 执行功能
            machine_gate.VerticalGate(analysis.block);
        }
    }
};
/**
 ** 魔晶上传
 */
export function PortalAboveTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:prompt_transport_above', analysis.block.bottomCenter());
                analysis.dimension?.playSound('conduit.activate', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
                machine_gate.AboveTeleport(analysis.block);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                analysis.dimension?.playSound('place.amethyst_block', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            };
            if (analysis.condition != 0 && analysis.condition != 9) beforeEvent();
            else if (analysis.condition == 9) afterEvent();
        }
    }
};
/**
 ** 魔晶下传
 */
export function PortalBelowTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:prompt_transport_below', analysis.block.center());
                analysis.dimension?.playSound('conduit.activate', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
                machine_gate.BelowTeleport(analysis.block);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                analysis.dimension?.playSound('place.amethyst_block', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            };
            if (analysis.condition != 0 && analysis.condition != 9) beforeEvent();
            else if (analysis.condition == 9) afterEvent();
        }
    }
};
/**
 ** 闪长岩桌
 */
export function DioriteTableTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 查询世界动态属性
             */
            const getProperty = server.world.getDynamicProperty('block:diorite_table') as string;
            if (!getProperty) {
                /**
                 ** 粒子信息
                 */
                const particles: string[] = [];
                for (let index = 0; index < 3; index++) { particles.push(derived_tools.AnalysisWeight(data_block.diorite_table_random_items).output) }
                /**
                 ** 绑定坐标与粒子信息
                 */
                const binding = JSON.stringify([{ x: analysis.block.x, y: analysis.block.y, z: analysis.block.z, particles }]);
                server.world.setDynamicProperty('block:diorite_table', binding);
                return;
            };
            /**
             ** 解析坐标与粒子信息
             */
            const unpack = JSON.parse(getProperty) as { x: number, y: number, z: number, particles: string[] }[];
            /**
             ** 筛选坐标
             */
            const intel = unpack.filter(value => math_tools.Vector.equals(value, analysis.block));
            // 当不存在对应坐标信息时
            if (intel.length == 0) {
                /**
                 ** 粒子信息
                 */
                const particles: string[] = [];
                for (let index = 0; index < 3; index++) { particles.push(derived_tools.AnalysisWeight(data_block.diorite_table_random_items).output) }
                unpack.push({ x: analysis.block.x, y: analysis.block.y, z: analysis.block.z, particles });
                server.world.setDynamicProperty('block:diorite_table', JSON.stringify(unpack));
            }
            // 当存在对应坐标信息时
            else {
                /**
                 ** 获取方块维度
                 */
                const dimension = analysis.dimension;
                /**
                 ** 创建粒子
                 * 
                 * @param name - 粒子名称
                 * @param offset - 偏移量
                 */
                const CreateCase = (name: string, offset: server.Vector3) => native_tools.TrySpawnParticle(dimension, name, math_tools.Vector.add(analysis.block, offset));
                // 生成信息中的粒子
                intel[0].particles.forEach((value, index) => CreateCase(value, { x: 0.5, y: 1 + (index * 0.05), z: 0.5 }));
            };
        }
    }
};
/**
 ** 丛林木椅
 */
export function JungleWoodChairTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 获取玩家队列
             */
            const players = analysis.dimension.getPlayers({ location: analysis.block.above()?.bottomCenter(), maxDistance: 0.5 });
            if (players.length == 0) return;
            players.forEach(player => player.playAnimation('animation.entity.sit_down.player'));
        }
    }
};
/**
 ** 造石单元
 */
export function StoneMachineTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                /**
                 ** 方块状态值
                 */
                const value = analysis.state.getState('STATE:value') as number;
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', value - 1);
            };
            /**
             ** 方块中继事件
             */
            function middleEvent() {
                // 播放音效 与 粒子效果
                analysis.dimension?.playSound('random.fizz', analysis.block.location);
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 5);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                // 播放音效 与 粒子效果
                analysis.dimension?.playSound('bucket.empty_lava', analysis.block.location);
                // 执行功能
                mineral_project.Solidify(analysis.block);
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 0);
            };
            /**
             ** 方块状态值
             */
            const value = analysis.state.getState('STATE:value') as number;
            if (value != 0 && value != 1) beforeEvent();
            else if (value == 0) middleEvent();
            else if (value == 1) afterEvent();
        }
    }
};
/**
 ** 金属锻压
 */
export function MetalFormingPressTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 方块前处理事件
             */
            function beforeEvent() {
                /**
                 ** 方块状态值
                 */
                const value = analysis.state.getState('STATE:value') as number;
                // 播放音效 与 粒子效果
                analysis.dimension?.playSound('block.stonecutter.use', analysis.block.location);
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', value + 1);
            };
            /**
             * * 方块后处理事件
             */
            function afterEvent() {
                // 播放音效 与 粒子效果
                analysis.dimension?.playSound('random.anvil_land', analysis.block.location);
                // 执行功能
                mineral_project.Forming(analysis.block);
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 0);
            };
            /**
             ** 方块状态值
             */
            const value = analysis.state.getState('STATE:value') as number;
            if (value != 7) beforeEvent();
            else if (value == 7) afterEvent();
        }
    }
};
/**
 ** 破坏核心
 */
export function DestroyTheCoreTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 执行功能
            mineral_project.Destroy(analysis.block, analysis.state.getState('minecraft:block_face') as string);
            // 复位状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 矿井单元
 */
export function MineralMachineTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                // 播放音效 与 粒子效果
                analysis.dimension?.playSound('block.stonecutter.use', analysis.block.location);
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', analysis.state.getState('STATE:value') as number + 1);
            };
            function afterEvent() {
                // 播放音效 与 粒子效果
                analysis.dimension?.playSound('random.anvil_land', analysis.block.location);
                // 执行功能
                mineral_project.Mine(analysis.block);
                // 复位状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 0);
            };
            if (analysis.state.getState('STATE:value') as number != 8) beforeEvent();
            else if (analysis.state.getState('STATE:value') as number == 8) afterEvent();
        }
    }
};
/**
 ** 能量节点
 */
export function EnergySupplyTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            // 执行功能
            energy_module.Supply(analysis.block, analysis.state.getState('STATE:energy') as number);
            // 复位状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
        }
    }
};
/**
 ** 风力动能
 */
export function WindPowerTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 方块状态值
             */
            const rotate = analysis.state.getState('STATE:rotate') as number;
            /**
             ** 方块状态值
             */
            const type = analysis.state.getState('STATE:stage') as number;
            // 赋值方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:rotate', rotate != 2 ? rotate + 1 : 0);
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', type != 9 ? type + 1 : 0);
            // 执行功能
            energy_module.Wind(analysis.block);
        }
    }
};
/**
 ** 魔晶储罐
 */
export function CrystalTankTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 检测目标块是否为能量节点
             */
            const onTag = analysis.block.above()?.getTags()?.includes('data_tag:energy_module.node') as boolean;
            /**
             ** 获取方块状态
             */
            const caching = analysis.state.getState('STATE:caching') as number;
            // 播放音效 与 粒子效果
            if (!onTag && analysis.state.getState('STATE:output') as number == 1) analysis.dimension?.playSound('block.grindstone.use', analysis.block.location);
            // 如果检测到能量节点
            if (onTag) {
                /**
                 ** 粒子效果索引值
                 */
                const index = math_tools.Random({ max: 4, min: 0 }, true);
                // 播放粒子效果
                switch (index) {
                    case 0:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_red', analysis.block.above()?.bottomCenter() as server.Vector3);
                        break;

                    case 1:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_blue', analysis.block.above()?.bottomCenter() as server.Vector3);
                        break;

                    case 2:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_green', analysis.block.above()?.bottomCenter() as server.Vector3);
                        break;

                    case 3:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_orange', analysis.block.above()?.bottomCenter() as server.Vector3);
                        break;

                    case 4:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_purple', analysis.block.above()?.bottomCenter() as server.Vector3);
                        break;

                    default: break;
                };
                // 赋值方块状态
                native_tools.TrySetPermutation(analysis.block, 'STATE:caching', caching + Math.floor(Math.random() * 2));
                // 替换储罐方块
                if (caching == 8) analysis.block.setPermutation(server.BlockPermutation.resolve('block_energy:empty_tank'));
                // 执行功能
                energy_module.Tank(analysis.block);
            };
            // 赋值方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:output', onTag ? 1 : 0);
        }
    }
};
/**
 ** 变换储罐
 */
export function TransformTankTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 辉光-魔晶储罐
             */
            const constant = server.BlockPermutation.resolve('block_energy:release_tank');
            // 播放粒子效果
            switch (math_tools.Random({ max: 4, min: 0 }, true)) {
                case 0:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_red', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 1:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_blue', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 2:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_green', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 3:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_orange', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 4:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_purple', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                default: break;
            };
            switch (math_tools.Random({ max: 4, min: 0 }, true)) {
                case 0:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_red', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 1:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_blue', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 2:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_green', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 3:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_orange', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 4:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_purple', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                default: break;
            };
            switch (math_tools.Random({ max: 4, min: 0 }, true)) {
                case 0:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_red', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 1:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_blue', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 2:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_green', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 3:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_orange', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                case 4:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_purple', analysis.block.above()?.bottomCenter() as server.Vector3);
                    break;

                default: break;
            };
            analysis.dimension.playSound('cauldron.explode', analysis.block.location);
            analysis.block.setPermutation(constant);
        }
    }
};
/**
 ** 动能分配
 */
export function AllocationPowerTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 检测目标块是否为能量节点
             */
            const onTag = analysis.block.above()?.getTags()?.includes('data_tag:energy_module.node') as boolean;
            if (!onTag) return;
            // 赋值方块状态
            native_tools.TrySetPermutation(analysis.block, 'STATE:output', 0);
            // 执行功能
            energy_module.Tank(analysis.block);
        }
    }
};
/**
 ** 熔岩质能
 */
export function MagmaPowerTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 获取计数值
             */
            const count = analysis.state.getState('STATE:count') as number;
            /**
             ** 获取熔岩量
             */
            const magma = analysis.state.getState('STATE:magma') as number;
            // 播放音效
            analysis.dimension?.playSound('fire.fire', analysis.block.location);
            // 执行功能
            energy_module.Magma(analysis.block);
            // 执行一定次数后修改方块状态
            blockTimer(analysis.block, 2,
                () => {
                    if (count == 0) {
                        native_tools.TrySetPermutation(analysis.block, 'STATE:count', 15);
                        native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma - 1);
                    }
                    else {
                        native_tools.TrySetPermutation(analysis.block, 'STATE:count', count - 1);
                    };
                }
            )
        }
    }
};
/**
 ** 水素质能
 */
export function WaterPowerTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 前处理事件
             */
            function beforeEvent() {
                /**
                 ** 空气方块
                 */
                const air = server.BlockPermutation.resolve('minecraft:air');
                /**
                 ** 水源方块
                 */
                const water = server.BlockPermutation.resolve('minecraft:water');
                /**
                 ** 锚点_a
                 */
                const anchor_a = math_tools.Vector.add(analysis.block.location, math_tools.Vector.CONSTANT_ONE);
                /**
                 ** 锚点_b
                 */
                const anchor_b = math_tools.Vector.add(analysis.block.location, math_tools.Vector.CONSTANT_LOSS_ONE);
                /**
                 ** 获取计数值
                 */
                const isWater = analysis.block.below()?.isLiquid as boolean;
                /**
                 ** 获取方块状态
                 */
                const current = analysis.state.getState('STATE:stage') as number;
                // 赋值 方块状态
                if (isWater) native_tools.TrySetPermutation(analysis.block, 'STATE:stage', current + 1);
                // 将 水源 置换为 空气
                native_tools.TryFillBlocks(analysis.dimension, anchor_a, anchor_b, air, { blockFilter: { includePermutations: [water] } });
            };
            /**
             * * 后处理事件
             */
            function afterEvent() { energy_module.Water(analysis.block) };
            if (analysis.state.getState('STATE:stage') as number !== 9) beforeEvent();
            else afterEvent();
        }
    }
};
/**
 ** 植树造木
 */
export function PlantingAndLoggingTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 前处理事件
             */
            function beforeEvent() {
                /**
                 ** 获取计数值
                 */
                const stage = analysis.state.getState('STATE:stage') as number;
                analysis.dimension.playSound('block.composter.fill_success', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', stage + 1);
            };
            /**
             * * 后处理事件
             */
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
                farming_project.Forestry(analysis.block);
            }
            if (analysis.state.getState('STATE:stage') as number !== 5) beforeEvent();
            else afterEvent();
        }
    }
};
/**
 ** 作物侦测
 */
export function CropDetectionTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 检测方块是否处于开启状态
             */
            const onTag = analysis.block.above()?.getTags()?.includes('data_tag:magic_cable.open') as boolean;
            if (onTag) analysis.dimension.playSound('block.composter.ready', analysis.block.location);
            if (onTag) farming_project.Detection(analysis.block);
        }
    }
};
/**
 ** 魔晶明灯
 */
export function MagicCrystalLampTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 获取方块状态
             */
            const light = analysis.state.getState('STATE:light') as number;
            if (analysis.condition as number <= 3 && light != 15) native_tools.TrySetPermutation(analysis.block, 'STATE:light', light + 1);
            if (analysis.condition as number >= 4 && light != 0) native_tools.TrySetPermutation(analysis.block, 'STATE:light', light - 1);
            if (analysis.condition as number == 6) native_tools.TrySetPermutation(analysis.block, 'STATE:light', 15);
            if (analysis.condition as number == 7) native_tools.TrySetPermutation(analysis.block, 'STATE:light', 0);
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    }
};
/**
 ** 水域天降
 */
export function WindAndRainTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 获取粒子类型
             */
            const particle = analysis.state.getState('STATE:particle') as string;
            /**
             ** 获取计数值
             */
            const stage = analysis.state.getState('STATE:stage') as number;
            /**
             ** 检测方块是否处于开启状态
             */
            const onTag = analysis.block.below()?.getTags()?.includes('data_tag:magic_cable.open') as boolean;
            if (!onTag) return;
            if (stage == 0) native_tools.TrySpawnParticle(analysis.dimension, 'constant:impact_rune_white', analysis.block.location);
            if (stage == 0) native_tools.TrySpawnParticle(analysis.dimension, particle, analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', stage != 3 ? stage + 1 : 0);
        }
    }
};
/**
 ** 脉冲尖峰
 */
export function PulsePeakCannonTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 检测方块是否处于开启状态
             */
            const onTag = analysis.block.below()?.getTags()?.includes('data_tag:magic_cable.open') as boolean;
            if (onTag) magic_weapon.PulsePeakCannon(analysis.block);
        }
    }
};
/**
 ** 曜石熔炉
 */
export function FurnaceTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             * * 前处理事件
             */
            function beforeEvent() {
                /**
                 * * 获取剩余石材数量
                 */
                const material = analysis.state.getState('STATE:material') as number;
                /**
                 * * 获取方块运行阶段
                 */
                const stage = analysis.state.getState('STATE:stage') as number;
                /**
                 * * 获取熔岩库存量
                 */
                const magma = analysis.state.getState('STATE:magma') as number;
                // 检测是否为 熔岩生成 阶段
                if (stage == 1 && material != 0) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:material', material - 1);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma + 1);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_0', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_1', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_2', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_3', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
                }
                else if (stage == 0) obsidian_smelting.Attrition(analysis.block);
            };
            /**
             * * 后处理事件
             */
            function afterEvent() {
                const direction_0 = analysis.block.offset({ x: 0, y: -1, z: -1 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank')
                const direction_1 = analysis.block.offset({ x: -1, y: -1, z: 0 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank')
                const direction_2 = analysis.block.offset({ x: 0, y: -1, z: 1 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank')
                const direction_3 = analysis.block.offset({ x: 1, y: -1, z: 0 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank')
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_0', direction_0 ? 1 : 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_1', direction_1 ? 1 : 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_2', direction_2 ? 1 : 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_3', direction_3 ? 1 : 0);
                obsidian_smelting.Pouring(analysis.block);
            }
            const magma = analysis.state.getState('STATE:magma') as number;
            if (magma != 8) beforeEvent();
            if (magma == 8) afterEvent();
        }
    }
};
/**
 ** 消耗星尘力
 */
export function EnergyExpendTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 查询能量消耗值
             */
            const expend = analysis.state.getState('STATE:energy_expend') as number;
            /**
             ** 查询剩余能量
             */
            const energy = realm_property.ExpendEnergy(analysis.block, expend);
            // 检测能量是否变动成功
            if (energy) native_tools.TrySetPermutation(analysis.block, 'STATE:energy_stage', 2);
            else native_tools.TrySetPermutation(analysis.block, 'STATE:energy_stage', 0);
        }
    }
};
/**
 ** 常规 物流网络 接收端
 */
export function RoutineLogisticsReceiverTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 获取 关于方块旋转 的 方块状态
             */
            const direction = analysis.state.getState('minecraft:cardinal_direction');
            /**
             ** 侦测 方块容器 并 提交 物品网络申请
             * 
             * @param {server.Block | undefined} target - 目标容器方块
             */
            function Detecting(target?: server.Block) {
                /**
                 ** 上方 的 物品展示框 的 物品信息
                 */
                const frame = analysis.block.above()?.getItemStack(1);
                /**
                 ** 指定的 方块 的 物品容器
                 */
                const container = target?.getComponent('inventory')?.container;
                // 检测 容器 展示框 剩余空间 是否满足要求
                if (!target || !frame || !container || container.emptySlotsCount == 0) return;
                /**
                 ** 物品网络频道
                 */
                const channel = frame.typeId;
                /**
                 ** 网络筛选类型
                 */
                const filter = container.getItem(0)?.typeId ?? frame.typeId;
                // 提交 物品网络申请
                routineLogisticsRequest.set(analysis.dimension.id + '•' + channel + '•' + filter, target.location);
            };
            // 基于 方块状态 旋转 容器读取方向
            switch (direction) {
                case 'south': Detecting(analysis.block.south()); break;

                case 'north': Detecting(analysis.block.north()); break;

                case 'east': Detecting(analysis.block.east()); break;

                case 'west': Detecting(analysis.block.west()); break;

                default: break;
            }
        }
    }
};
/**
 ** 跨界 物流网络 接收端
 */
export function SurpassLogisticsReceiverTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 获取 关于方块旋转 的 方块状态
             */
            const direction = analysis.state.getState('minecraft:cardinal_direction');
            /**
             ** 侦测 方块容器 并 提交 物品网络申请
             * 
             * @param {server.Block | undefined} target - 目标容器方块
             */
            function Detecting(target?: server.Block) {
                /**
                 ** 上方 的 物品展示框 的 物品信息
                 */
                const frame = analysis.block.above()?.getItemStack(1);
                /**
                 ** 指定的 方块 的 物品容器
                 */
                const container = target?.getComponent('inventory')?.container;
                // 检测 容器 展示框 剩余空间 是否满足要求
                if (!target || !frame || !container || container.emptySlotsCount == 0) return;
                /**
                 ** 物品网络频道
                 */
                const channel = frame.typeId;
                /**
                 ** 网络筛选类型
                 */
                const filter = container.getItem(0)?.typeId ?? frame.typeId;
                // 提交 物品网络申请
                surpassDimensionRequest.set(channel + '•' + filter, [target.dimension, target.location]);
            };
            // 基于 方块状态 旋转 容器读取方向
            switch (direction) {
                case 'south': Detecting(analysis.block.south()); break;

                case 'north': Detecting(analysis.block.north()); break;

                case 'east': Detecting(analysis.block.east()); break;

                case 'west': Detecting(analysis.block.west()); break;

                default: break;
            }
        }
    }
};
/**
 ** 常规 物流网络 发送端
 */
export function RoutineLogisticsSenderTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 上方 的 物品展示框 的 物品信息
             */
            const frame = analysis.block.above()?.getItemStack(1);
            // 检测 展示框 能量 请求数量 是否满足要求
            if (!frame || !realm_property.ExpendEnergy(analysis.block, -20) || routineLogisticsRequest.size < 1) return;
            /**
             ** 物品网络频道
             */
            const channel = [...routineLogisticsRequest].filter(
                info => {
                    const split = info[0].split('•');
                    return split[0] == analysis.dimension.id && split[1] == frame.typeId
                }
            );
            /**
             ** 附近的方块容器
             */
            const containers = [
                analysis.block.west()?.getComponent('inventory')?.container,
                analysis.block.east()?.getComponent('inventory')?.container,
                analysis.block.north()?.getComponent('inventory')?.container,
                analysis.block.south()?.getComponent('inventory')?.container,
            ];
            /**
             ** 重构 物品请求信息
             */
            const judge = new Map<string, server.Vector3>(channel.map(info => [info[0].split('•')[2], info[1]]));
            // 遍历容器
            containers.forEach(
                container => {
                    // 检测容器是否存在
                    if (!container) return;
                    // 遍历容器中的物品
                    for (let index = 0; index < container.size; index++) {
                        /**
                         ** 获取容器中的物品
                         */
                        const item = container.getItem(index); if (!item) continue;
                        /**
                         ** 检测物品是否在请求列表上
                         */
                        const result = judge.get(item.typeId); if (!result) continue;
                        /**
                         ** 获取发出请求的方块
                         */
                        const block = analysis.dimension.getBlock(result); if (!block) continue;
                        /**
                         ** 获取接收物品的方块容器
                         */
                        const inventory = block.getComponent('inventory')?.container; if (!inventory) continue;
                        // 迁移物品
                        inventory.addItem(item);
                        container.setItem(index);
                        return;
                    }
                }
            );
            // 清除 物品网络申请
            routineLogisticsRequest = new Map<string, server.Vector3>(
                [...routineLogisticsRequest].filter(
                    info => {
                        /**
                         ** 拆分 维度 频道 类型
                         */
                        const split = info[0].split('•');
                        // 检测 维度 频道 类型 是否符合
                        return split[0] != analysis.dimension.id || split[1] != frame.typeId
                    }
                )
            );
        }
    }
};
/**
 ** 跨界 物流网络 发送端
 */
export function SurpassLogisticsSenderTrigger(): server.BlockCustomComponent {
    return {
        onTick(source: server.BlockComponentTickEvent) {
            /**
             * * 方块组件参数 的 解构
             */
            const analysis = TickComponentTrigger(source);
            /**
             ** 上方 的 物品展示框 的 物品信息
             */
            const frame = analysis.block.above()?.getItemStack(1);
            // 检测 展示框 能量 请求数量 是否满足要求
            if (!frame || !realm_property.ExpendEnergy(analysis.block, -30) || surpassDimensionRequest.size < 1) return;
            /**
             ** 物品网络频道
             */
            const channel = [...surpassDimensionRequest].filter(info => info[0].split('•')[0] == frame.typeId);
            /**
             ** 附近的方块容器
             */
            const containers = [
                analysis.block.west()?.getComponent('inventory')?.container,
                analysis.block.east()?.getComponent('inventory')?.container,
                analysis.block.north()?.getComponent('inventory')?.container,
                analysis.block.south()?.getComponent('inventory')?.container,
            ];
            /**
             ** 重构 物品请求信息
             */
            const judge = new Map<string, [server.Dimension, server.Vector3]>(channel.map(info => [info[0].split('•')[1], info[1]]));
            // 遍历容器
            containers.forEach(
                container => {
                    // 检测容器是否存在
                    if (!container) return;
                    // 遍历容器中的物品
                    for (let index = 0; index < container.size; index++) {
                        /**
                         ** 获取容器中的物品
                         */
                        const item = container.getItem(index); if (!item) continue;
                        /**
                         ** 检测物品是否在请求列表上
                         */
                        const result = judge.get(item.typeId); if (!result) continue;
                        /**
                         ** 获取发出请求的方块
                         */
                        const block = result[0].getBlock(result[1]); if (!block) continue;
                        /**
                         ** 获取接收物品的方块容器
                         */
                        const inventory = block.getComponent('inventory')?.container; if (!inventory) continue;
                        // 迁移物品
                        inventory.addItem(item);
                        container.setItem(index);
                        return;
                    }
                }
            );
            // 清除请求信息
            surpassDimensionRequest = new Map<string, [server.Dimension, server.Vector3]>(
                [...surpassDimensionRequest].filter(info => info[0].split('•')[0] != frame.typeId)
            );
        }
    }
};